﻿using Hangfire;
using Microsoft.Extensions.DependencyInjection;

namespace PHMEE.BackgroundJobs
{
    public static class PHMEEBackgroundJobsExtension
    {
        /// <summary>
        /// 注册业务Job
        /// </summary>
        /// <param name="service"></param>
        public static void ConfigurePhmeeJob(this IServiceProvider service)
        {
            UseAuditLogClearJob(service);
        }

        /// <summary>
        /// 清理审计日志Job
        /// </summary>
        /// <param name="service"></param>
        public static void UseAuditLogClearJob(this IServiceProvider service)
        {
            var job = service.GetService<AuditLogClearJob>();

            RecurringJob.AddOrUpdate("清理审计日志", () => job.ExcuteAsync(), PHMEECronType.Month());
        }

        /// <summary>
        /// 周期性作业：测试Job
        /// </summary>
        /// <param name="service"></param>
        public static void UseTestJob(this IServiceProvider service)
        {
            var job = service.GetService<TestJob>();

            RecurringJob.AddOrUpdate("测试定时任务", () => job.ExcuteAsync(), PHMEECronType.Minute());
        }

        /// <summary>
        /// 队列作业：测试Job
        /// </summary>
        /// <param name="service"></param>
        public static void UseTestQueueJob(this IServiceProvider service)
        {
            var job = service.GetService<TestQueueJob>();

            BackgroundJob.Enqueue(() => job.ExcuteAsync());
        }
    }
}
